<?php

namespace app\admin\controller\general;

use app\admin\model\Admin;
use app\admin\model\User;
use app\common\controller\Backend;
use fast\Random;
use think\Session;

/**
 * 站点配置
 *
 * @icon fa fa-user
 */
class Site extends Backend
{

    /**
     * 查看
     */
    public function index()
    {
        $adminInfo = Session::get('admin');
        $userModel = new User();
        $siteInfo = $userModel->where('id',$adminInfo['site_id'])->find();
        $this->assign('siteInfo',$siteInfo);
        return $this->view->fetch();
    }

    /**
     * 更新站点信息
     */
    public function update()
    {
        if ($this->request->isPost())
        {
            $params = $this->request->post("row/a");
            if (!empty($params['id']) && !empty($params['site_number']))
            {
                $userModel = new User();
                if(strlen($params['site_number'])!=10)$this->error('家园编号为10位数字');
                $siteNumberInfo = $userModel->where('site_number',$params['site_number'])->find();
                if($siteNumberInfo)$this->error('此编号已存在');
                $userModel->where('id',$params['id'])->setField('site_number',$params['site_number']);
                $this->success('成功');
            }
            $this->error('家园编号不可为空');
        }
        return;
    }

}
